package com.anxinr.controller;

import com.anxinr.pojo.entity.TestCase;
import com.anxinr.pojo.entity.Users;
import com.anxinr.result.Result;
import com.anxinr.service.ITestCaseService;
import com.anxinr.service.IUsersService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.IService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @author anxinr
 */
@Slf4j
@RestController
@RequestMapping("/testcase")
public class TestCaseController {
    @Autowired
    private ITestCaseService testCaseService ;

    @PostMapping("/query")
    public Result<IPage<TestCase>> query(@RequestBody TestCase testCase){
        return new Result(testCaseService.queryUsers(testCase)) ;
    }

    @PostMapping("/save")
    public Result save(@RequestBody TestCase testCase) throws Exception {
        try {
            return new Result(testCaseService.save(testCase)) ;
        }catch (Exception e){
            e.printStackTrace();
            throw e ;
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody TestCase testCase) throws Exception {
        try {
            return new Result(testCaseService.updateById(testCase)) ;
        }catch (Exception e){
            e.printStackTrace();
            throw e ;
        }
    }

    @GetMapping("/remove")
    public Result remove(@RequestParam("cname") String cname){
        try {
            LambdaUpdateWrapper<TestCase> wrapper = new LambdaUpdateWrapper<>();
            wrapper.eq(TestCase::getCname,cname);
            testCaseService.remove(wrapper);
            return Result.success() ;
        }catch (Exception e){
            e.printStackTrace();
            throw e ;
        }
    }

}
